

package com.zy.controller;

import com.github.pagehelper.PageInfo;
import com.zy.entity.Position;
import com.zy.entity.vo.RoleIds;
import com.zy.service.PositionService;
import com.zy.util.R;
import javax.annotation.Resource;

import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping({"position"})
public class PositionController {

    @Resource
    PositionService positionService;

    @GetMapping({"getById/{id}"})
    public R getById(@PathVariable Integer id) {
        Position position = this.positionService.getById(id);
        return R.ok().put("menu", position);
    }

    @PutMapping({"save"})
    public R save(@RequestBody Position position) {
        this.positionService.save(position);
        return R.ok();
    }

    @PostMapping({"updateById"})
    public R updateById(@RequestBody Position position) {
        this.positionService.updateById(position);
        return R.ok();
    }

    @PostMapping({"status/{id}"})
    public R status(@PathVariable Integer id) {
        this.positionService.status(id);
        return R.ok();
    }

    @PostMapping({"page/{page}/{limit}"})
    public R tree(@PathVariable Integer page, @PathVariable Integer limit) {
        PageInfo<Position> pageInfo = this.positionService.page( page, limit);
        return R.ok().put("pageInfo", pageInfo);
    }

    @DeleteMapping({"delete/{id}"})
    public R delete(@PathVariable Integer id) {
        this.positionService.delete(id);
        return R.ok();
    }

    @GetMapping("getByStaffId/{staffId}")
    public R getByStaffId(@PathVariable Integer staffId) {
        List<Position> positionList = this.positionService.getByStaffId(staffId);
        return R.ok().put("positionList",positionList);
    }

    @PostMapping("setByStaffId/{staffId}")
    public R setByStaffId(@RequestBody RoleIds roleIds, @PathVariable Integer staffId) {
        this.positionService.setByStaffId(staffId,roleIds.getRoleIds());
        return R.ok();
    }
    @GetMapping("all")
    public R all() {
        List<Position> positionList= this.positionService.all();
        return R.ok().put("positionList",positionList);
    }

}
